package com.fr.chart.core.glyph;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.ColorInfo;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.math.Projection;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.shape3d.Cylinder;
import com.fr.chart.shape3d.Pie3D;
import java.awt.geom.Arc2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.awt.geom.Rectangle2D;

public class Pie3DPlotGlyph extends PiePlotGlyph
{
  private static final long serialVersionUID = -8454922131125531977L;
  public static final String XML_TAG = "Pie3DPlotGlyph";
  private int depth = 20;
  private Projection projection = new Projection();

  public boolean supportJSDrawing()
  {
    return false;
  }

  public void layoutAxisGlyph()
  {
  }

  public void layoutDataSeriesGlyph()
  {
    for (int i = 0; i < getCategoryCount(); ++i)
    {
      instancePieNumber();
      double d1 = getPieDimension();
      double d2 = d1 / (2.0D + 2 * getSeparatePercent() / 100.0D);
      double d3 = getStartAngle();
      double d4 = getSeparatePercent() / 100.0D * d2;
      Pie3D localPie3D = new Pie3D();
      localPie3D.setProjection(getProjection());
      for (int j = 0; j < getSeriesSize(); ++j)
      {
        DataSeries localDataSeries = getSeries(j);
        DataPoint localDataPoint = localDataSeries.getDataPoint(i);
        if (localDataPoint.isValueIsNull())
          break label363:
        double d5 = getHalfAngle(d3, j, i);
        double d6 = (i + 0.5D) * getBounds().getWidth() / getCategoryCount();
        Point2D.Double localDouble = new Point2D.Double(d6, getBounds().getHeight() / 2.0D);
        Cylinder localCylinder = new Cylinder(0.0D, getDepth(), d2);
        localCylinder.setX(localDouble.getX() + d4 * Math.cos(Math.toRadians(d5)));
        localCylinder.setY(localDouble.getY() - d4 * Math.sin(Math.toRadians(d5)));
        localCylinder.setStart(d3);
        localCylinder.setExtent(getPercent(j, i) * 360.0D);
        localCylinder.setProjection(getProjection());
        localCylinder.getColorInfo().dealCondition(getSeriesCollection(), j);
        localPie3D.addCylinder(localCylinder);
        if (j == 0)
          localDataPoint.setDrawImpl(localPie3D);
        TextGlyph localTextGlyph = localDataPoint.getDataLabel();
        dealLabelBounds(localCylinder.top().getBounds2D(), localDouble, d5, j, i, localTextGlyph, d1 * 0.5D);
        dealLeadLine(localCylinder.top(), localDataPoint, localTextGlyph, j, d5);
        d3 += getPercent(j, i) * 360.0D;
      }
    }
    label363:
  }

  public void setProjection(Projection paramProjection)
  {
    this.projection = paramProjection;
  }

  public Projection getProjection()
  {
    return this.projection;
  }

  public void setDepth(int paramInt)
  {
    this.depth = paramInt;
  }

  public int getDepth()
  {
    return this.depth;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Pie3DPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("depth", this.depth).end();
    if (this.projection != null)
      this.projection.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("depth")) != null)
          this.depth = Integer.valueOf(str2).intValue();
      }
      else if (str1.equals("Projection"))
      {
        this.projection = ((Projection)paramXMLableReader.readXMLObject(new Projection()));
      }
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof Pie3DPlotGlyph))
      return false;
    Pie3DPlotGlyph localPie3DPlotGlyph = (Pie3DPlotGlyph)paramObject;
    if (!(super.equals(localPie3DPlotGlyph)))
      return false;
    if (localPie3DPlotGlyph.depth != this.depth)
      return false;
    return (Equals.equals(localPie3DPlotGlyph.projection, this.projection));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Pie3DPlotGlyph localPie3DPlotGlyph = (Pie3DPlotGlyph)super.clone();
    if (this.projection != null)
      localPie3DPlotGlyph.projection = ((Projection)this.projection.clone());
    return localPie3DPlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("depth", this.depth);
    localJSONObject.put("projection", this.projection.toJSONObject());
    return localJSONObject;
  }
}